package tcss543;

import java.io.*;

import tcss543.multiplehelpers.*;
import tcss543.singlehelper.*;
import tcss543.auction.Auction;
import tcss543.auction.AuctionResult;
import tcss543.test.*;

public class Program {
	public static void main(String args[]) throws IOException {
		
		int noOfRuns = 10000;
		
		Matcher[] matchers = new Matcher[] {
				new MultipleHelpersMatcherRandom(),
				new MultipleHelpersMatcherLargestFirst(),
				new MultipleHelpersMatcherSmallestFirst(),
				new MultipleHelpersMatcherLeastWasteFirst(),
				new SingleHelper()
		};
		
		TestDataGenerator generator = new TestDataGenerator();
		Auction auction = new Auction();
		PrintWriter writer = new PrintWriter(args[0]);

		writer.println("Run,Matcher,Requestors 1,Units 1,Helpers 1,Avg helpers per req 1,Requestors 2,Units 2,Helpers 2,Avg helpers per req 2,Profit");
		
		for (int r = 0; r < noOfRuns; r++) {
			DeviceGraph graph = generator.generateTestGraph();
			MatchingAnalyzer analyzer = new MatchingAnalyzer(graph);
			
			for (int m = 0; m < matchers.length; m++) {
				int[][] matching = matchers[m].findMatching(graph);
				MatchingSummary summary1 = analyzer.analyze(matching);
				AuctionResult auctionResult = auction.doAuction(graph, matching);
				MatchingSummary summary2 = analyzer.analyze(auctionResult.getMatching());
				writer.println(
						r + "," + m + ","
						+ summary1.matchedRequestorCount + ","
						+ summary1.matchedRequestedUnits + ","
						+ summary1.matchedHelperCount + ","
						+ summary1.avgHelpersPerRequestor + ","
						+ summary2.matchedRequestorCount + ","
						+ summary2.matchedRequestedUnits + ","
						+ summary2.matchedHelperCount + ","
						+ summary2.avgHelpersPerRequestor + ","
						+ auctionResult.getProfit());				
			}
		}
		
		writer.close();
	}
}
